package com.chance.cc.crawler.development.bootstrap.autohome;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.core.downloader.HttpRequest;
import com.chance.cc.crawler.core.downloader.http.HttpClientDownloader;
import com.chance.cc.crawler.core.downloader.http.HttpClientGenerator;
import com.chance.cc.crawler.core.downloader.proxy.SiteConfigProxyProvider;
import org.junit.Test;

/**
 * @ClassName keyword
 * @Description TODO
 * @Author songding
 * @Date 2021/10/11 15:03
 * @Version 1.0
 **/
public class RemoveKeyword {
    @Test
    public void test(){
        HttpClientDownloader downloader = new HttpClientDownloader();
        downloader.setClientGenerator(new HttpClientGenerator());
        downloader.setProxyProvider(new SiteConfigProxyProvider());
        HttpConfig httpConfig = HttpConfig.me("auto");
        HttpRequest httpRequest = new HttpRequest();
        httpRequest.setResponseCharset("UTF-8");
        httpRequest.setMethod("get");
        httpRequest.setUrl("http://192.168.1.217:9599/v1/meta/autohome/keys?site=bmwKw");
        HttpPage download = downloader.download(httpRequest, httpConfig);
        String rawText = download.getRawText();
        JSONObject jsonObject = JSONObject.parseObject(rawText);
        JSONArray content = jsonObject.getJSONArray("content");
        for (Object obj :content){
            JSONObject jsonObject1 = JSONObject.parseObject(String.valueOf(obj));
            String keyword = jsonObject1.getString("keyword");
            System.out.println(keyword);
        }
    }
}
